library(SparkR)
sparkR.session(appName = "SparkR-ML-als-example")

dataTrain <- list(
  list(0, 0, 4.0), 
  list(0, 1, 2.0), 
  list(1, 1, 3.0),
  list(1, 2, 4.0), 
  list(2, 1, 1.0), 
  list(2, 2, 5.0),
  list(3, 2, 5.0)
)

dataTest <- list(
  list(3, 1)
)


df <- createDataFrame(dataTrain, c("userId", "movieId", "rating"))

training <- df
test <- createDataFrame(dataTest, c("userId", "movieId", "rating"))

model <- spark.als(
  training, 
  maxIter = 5, 
  regParam = 0.01, 
  userCol = "userId",
  itemCol = "movieId", 
  ratingCol = "rating"
)

summary(model)

predictions <- predict(model, test)

head(predictions)

sparkR.session.stop()
